
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })

exports.main = async (event, context) => {
  const db = cloud.database()
  const wxContext = cloud.getWXContext()
  
  try {
    const result = await db.collection('account')
      .where({
        _id: event.accountId
      })
      .update({
        data: {
          balance: event.balance,
          after: event.after,
          updateTime: db.serverDate()
        }
      })
    return {
      code: 0,
      data: result,
      message: '更新成功'
    }
  } catch (err) {
    return {
      code: -1,
      message: err.message
    }
  }
}